import java.util.Arrays;
import java.util.Comparator;

public class ComparatorTest implements Comparator<ComparatorTest.Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }

    static class Student  {
        private String name;
        private int id;
        private int age;

        public Student(String name, int id, int age) {
            this.name = name;
            this.id = id;
            this.age = age;
        }



        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", id=" + id +
                    ", age=" + age +
                    '}';
        }
    }

    public static void main(String[] args) {
        Student student1 = new Student("li",3,20);
        Student student2 = new Student("wang",1,24);
        Student student3 = new Student("niu",2,22);
        Student[] students = new Student[]{student1,student2,student3};
        Arrays.sort(students,new ComparatorTest());
        System.out.println(Arrays.toString(students));
    }
}
